package com.wonders.frame.controller.core;

import com.gcr.server.response.Response;
import com.wonders.frame.common.Enum.ResponseCodeEnum;

import java.util.Objects;

public abstract class AbstractController {
    public Response getResponse(ResponseCodeEnum e) {
        if (Objects.isNull(e)) {
            return errorResponse();
        }
        return getResponse(e.getResult(), e.getCode(), e.getMsg());
    }
    public Response getResponse(Object data, Integer code, String msg){
        Response response = getResponseWithoutMsg(data, code);
        response.setMsg(msg);
        return response;
    }
    public Response getResponseWithoutMsg(Object data, Integer code){
        Response response = getResponseWithCode(code);
        response.setContent(data);
        return response;
    }
    public Response getResponseWithCode(Integer code){
        Response response = new Response();
        response.setCode(code);
        return response;
    }
    public Response getResponseWithoutData(Integer code, String msg){
        Response response = new Response();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public Response successResponse(Object data){
        Response response=new Response();
        response.setCode(ResponseCodeEnum.SUCCESS.getCode());
        response.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        response.setContent(data);
        return response;
    }

    public Response errorResponse(){
        Response response=new Response();
        response.setCode(ResponseCodeEnum.SYSTEM_ERROR.getCode());
        response.setMsg(ResponseCodeEnum.SYSTEM_ERROR.getMsg());
        response.setContent(null);
        return response;
    }

    public Response errorResponse(Integer code,String msg,Object content){
        Response response=new Response();
        response.setCode(code);
        response.setMsg(msg);
        response.setContent(content);
        return response;
    }

    public Response errorResponse(ResponseCodeEnum responseCodeEnum,Object content){
        Response response=new Response();
        response.setCode(responseCodeEnum.getCode());
        response.setMsg(responseCodeEnum.getMsg());
        response.setContent(content);
        return response;
    }
}
